﻿using System.Collections.Generic;
using Cms.Domain;
using Cms.Domain.RepositoryInterfaces;
using NHibernate;
using NHibernate.Criterion;

namespace Cms.Data
{
    public class PermissionRepository : BaseRepository, IPermissionRepository
    {
        #region IPermissionRepository Members

        public void SavePermission(Permission permission)
        {
            Session.Save(permission);
            Session.Flush();
        }

        public IList<Permission> GetPermissions()
        {
            return Session.CreateQuery("from Permission p where p.Parent = null").List<Permission>();
        }

        public Permission GetPermission(int id)
        {
            return Session.Get<Permission>(id);
        }

        #endregion
    }
}